using Microsoft.UI.Xaml;
using Microsoft.Web.WebView2.Core;
using Windows.Foundation;

namespace PDFHelper
{
    public sealed partial class MainWindow : Window
    {
        public MainWindow() => InitializeComponent();
        private void PrintButton_Click(object sender, RoutedEventArgs e)
        {
            CoreWebView2PrintSettings settings = MyWebView2.CoreWebView2.Environment.CreatePrintSettings();
            settings.MarginBottom = 0;
            settings.MarginLeft = 0;
            settings.MarginRight = 0;
            settings.MarginTop = 0;
            // 设置A5纸张尺寸 (148mm × 210mm)
            // 转换为英寸：148mm ≈ 5.83英寸，210mm ≈ 8.27英寸
            settings.PageWidth = 5.83;
            settings.PageHeight = 8.27;
            IAsyncOperation<bool> result = MyWebView2.CoreWebView2.PrintToPdfAsync(@"E:\Project\Test\PDFHelper\PDFHelper\bin\x64\Debug\net8.0-windows10.0.19041.0\test.pdf", settings);
        }
    }
}
